<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ page import="java.io.*,java.util.*" %>
<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import="org.apache.commons.fileupload.disk.*" %>
<%@ page import="org.apache.commons.fileupload.servlet.*" %>

<%@page import="com.buvaka.UpdateLinestylesFile"%>


<%@page import="java.net.UnknownHostException"%>
<%@ page import = "com.mongodb.*" %>

<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8"/>
    <title>Добавить тип связи</title>
    <script type="text/javascript" src="js/jscolor/jscolor.js"></script> <!-- to select color  -->
</head>
<body>

<%
    try{
        MongoClient client = new MongoClient();
        DB db = client.getDB("gis");
        DBCollection categories = db.getCollection("categories");
        request.setAttribute("client", client);
        request.setAttribute("categories", categories);
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
%>


<form action="AddLineStyle.jsp" method="post">
    Имя: <input type="text" name="name" />
    <br/>
    Цвет: <input class="color" name="color"/>
    <br/>
    <input type="submit" value="Сохранить" />
</form>


<%
	if (request.getParameter("name") != "" && request.getParameter("color") != "" && request.getParameter("name") != null && request.getParameter("color") != null) {

		try{
			MongoClient client = (MongoClient)request.getAttribute("client");
			DB db = client.getDB("gis");
			DBCollection styles = db.getCollection("lineStyles");
			
			String DASH = "#";
			BasicDBObject style = new BasicDBObject("_id", request.getParameter("name")).append("color", DASH + request.getParameter("color"));
			              
			
			styles.insert(style);
			
			UpdateLinestylesFile.update(client);
		
		
		
		} catch (Exception e) {
			e.printStackTrace();
		}	

}
%>

</body>
</html>
